package com.songqi.common.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

import java.util.Collections;

public class CodeGenerator {



    public static void main(String[] args) {


        String dbUrl = "jdbc:mysql://1.13.172.34:3306/gaussian_property";
        String username = "root";
        String password = "9beutkac3b3750A4!";
        String author = "songqi(13776346982)";
        String packageName = "com.gaussian.property.module.biz";
        String[] tablePrefix = new String[]{"aud", "sys", "test", "flw", "biz", "t_item"};
        String[] tables = new String[]{"user_read_project_alert"};
        String outputDir = System.getProperty("user.dir") + "/modules/module-biz/src/main/java";
        String mapperXmlDir = System.getProperty("user.dir") + "/modules/module-biz/src/main/resources/mapper";

        FastAutoGenerator.create(dbUrl, username, password)
            .globalConfig(builder -> {
                builder.author(author) // 设置作者
                    .outputDir(outputDir); // 指定输出目录
            })
            .packageConfig(builder -> {
                builder.parent(packageName) // 设置父包名
                    .moduleName("") // 设置模块名
                    .pathInfo(Collections.singletonMap(OutputFile.mapperXml, mapperXmlDir)); // 设置mapper XML文件生成路径
            })
            .strategyConfig(builder -> {
                builder.addInclude(tables) // 设置需要生成的表名
                    .addTablePrefix(tablePrefix); // 设置表前缀
            })
            .templateConfig(builder -> {
                // 设置自定义模板的路径
                builder.entity("/templates/entity.java.vm")
//                        .controller("/templates/controller.java.vm")
                        .service("/templates/service.java.vm")
                        .serviceImpl("/templates/serviceImpl.java.vm")
                        .mapper("/templates/mapper.java.vm")
                        .mapperXml("/templates/mapper.xml.vm");
            })
            .templateEngine(new VelocityTemplateEngine()) // 使用Velocity引擎模板
            .execute();
    }
}
